import {mileSecondToDate} from '../../../assets/js/help.js'
export default {
  data() {
    return {
      isShowTree: true,
    }
  },
  created() {
  },
  methods: {
    getList() {
      let params = $.extend({}, this.searchParams, this.otherParams);
      this.getOfflineRecordList(params);
    },
    getOfflineRecordList(aparams){
      let self = this,
      params = {
        page: this.pageNumber,
        rp: this.pageSize
      };
      params = $.extend({}, params, aparams);
      API.fetchGet('park/emergency/pageListOfCloudParkCameraWarning.do',params).then(res=>{
        let data = res.data
        let rows = data.rows
        self.tbodysInfo = [];
        self.total = data.total;
        for(let i = 0; i<rows.length; i++){
          self.tbodysInfo.push(rows[i])
        }
      },err=>{})
    },
    openSelectParkModal(modalName) {
      var _self = this;
      _self.toOpenModal(modalName, 2);
      this.initParkTree("ParkTree");
    },
    initParkTree(treeId) {
      var _self = this;
      api.fetchGet('/parkingBaseData/getParkingBaseDataWithAgreementTree.do', {})
          .then(res => {
            var data = res;
            if (data != null) {
                var nodes = data.data;
                var jsonStr = JSON.stringify(nodes);

                jsonStr = jsonStr.replace(/(\"isArea\"\:true\,)/g, '"isArea": true,"chkDisabled":true, "nocheck":true,');
                nodes = JSON.parse(jsonStr);
                var settings = {
                    check: {
                        enable: true,
                        chkStyle: "radio",
                        radioType: "all"
                    },
                    view: {
                        showIcon: false,
                        showLine: false,
                    },
                    callback: {
                        onClick: function (event, treeId, treeNode) {
                            var treeObj = $.fn.zTree.getZTreeObj('ParkTree');
                            treeObj.checkNode(treeNode, true, false);
                            if (treeNode.isArea) {
                                return;
                            }
                        },
                    }
                };
                $.fn.zTree.destroy("ParkTree");

                var treeObj = $.fn.zTree.init($("#ParkTree"), settings, nodes);
                treeObj.expandAll(true);

            } else {
                _self.showToast('暂时没有停车场可选', 2, 3000);
            }
        }, err => { })
      },
    selectParkSure(){
      var self = this,
          nodes = [];
      var treeObj = $.fn.zTree.getZTreeObj("ParkTree");
      nodes = treeObj.getCheckedNodes(true); // 获取tree被勾选的节点
      if(nodes && nodes.length>0){
        var p = nodes[0];
        self.closed('selectParkModal', 2);
      }else{
        this.showToast('请选择一个停车场', 0, 2000)
        return;
      }
    },
    exportData() {
      let self = this;
      let theadsArr = []
      for (let i = 0; i < self.theadsInfo.length; i++) {
        if (self.theadsInfo[i].checked) {
          theadsArr.push(self.theadsInfo[i].prop)
        }
      }
      let params = {
        meterList: theadsArr.join(',')
      };

      params = $.extend({}, params, this.searchParams, this.otherParams);
      self.showDialog("确认导出该报表?", '', function () {
        self.toExportAsync('park/emergency/exportCloudParkCameraWarning.do', params);
      });
    },
  }
}